<?php

namespace Apipad\Controller;
//私人定制和团体定制
header("content-type:application/json;charset=utf-8");

class SrdzController extends ComController
{
    //根据性别 身高 体重  品类查询信息
    public function get_mysqlcc()
    {
        $detail = I('post.');
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $sex = $detail['sex'] ?: 1;
        $high = $detail['high'] ?: 0;
        $cate_id = $detail['cate_id'] ?: 0;
        $weight = $detail['weight'] ?: 0;
        if (empty($high)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入身高";
            exit(json_encode($data_cc));
        }
        if (empty($cate_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "cate_id参数错误";
            exit(json_encode($data_cc));
        }
        //根据大类ID 查询上衣或者裤子
        $user_mysql_cate = M("user_mysql_default_cate");

        $mysql_child_count = $user_mysql_cate->where(['pid' => $cate_id, 'isdel' => 0])->count();
        $uid = UID;
        if ($mysql_child_count > 0) {
            $jo_res = $weight % 2;
            if ($jo_res != 0) {
                $weight = bcadd($weight, 1);
            }


            $cate_id2 = $cate_id1 = 0;
            if ($cate_id) {
                $cate_id1 = $user_mysql_cate->where(['pid' => $cate_id, 'stype' => 1, 'sht_c' => 0, 'isdel' => 0])->getField('id');
                $cate_id2 = $user_mysql_cate->where(['pid' => $cate_id, 'stype' => 1, 'sht_c' => 1, 'isdel' => 0])->getField('id');
            }
            //衣服
            $where['isdel'] = 0;
            $where['uid'] = $uid;
            $where['sex'] = $sex;
            $where['high'] = $high;
            $where['cat_id'] = $cate_id1;
            $where['weight'] = $weight;
            //裤子
            $fyst['isdel'] = 0;
            $fyst['uid'] = $uid;
            $fyst['sex'] = $sex;
            $fyst['high'] = $high;
            $fyst['cat_id'] = $cate_id2;
            $fyst['weight'] = $weight;
            $result['shagnyi_info'] = $user_mysql_list->where($where)->find();
            $result['kuzi_info'] = $user_mysql_listc->where($fyst)->find();
        } else {
            $cate_info = $user_mysql_cate->where(['id' => $cate_id, 'stype' => 1, 'isdel' => 0])->find();
            if ($cate_info['sht_c'] == 1) {
                //下装
                $fyst['isdel'] = 0;
                $fyst['uid'] = $uid;
                $fyst['sex'] = $sex;
                $fyst['high'] = $high;
                $fyst['cat_id'] = $cate_id;
                $fyst['weight'] = $weight;
                $result['kuzi_info'] = $user_mysql_listc->where($fyst)->find();
                $result['shagnyi_info'] = [];
            } else {
                //上装
                $where['isdel'] = 0;
                $where['uid'] = $uid;
                $where['sex'] = $sex;
                $where['high'] = $high;
                $where['cat_id'] = $cate_id;
                $where['weight'] = $weight;
                $result['kuzi_info'] = [];
                $result['shagnyi_info'] = $user_mysql_list->where($where)->find();
            }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['info'] = $result;
        exit(json_encode($data_cc));
    }


    public function getSizeFields()
    {
        $detail = I('post.', '', 'strip_tags');
        $uid = UID;
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $sex = $detail['sex'] ?: 1;
        $high = $detail['high'] ?: 0;
        $cate_ids = json_decode($detail['cate_id'],true) ;
        $weight = $detail['weight'] ?: 0;
        if($weight % 2 ===1){
            $weight++;
        }
        //根据大类ID 查询上衣或者裤子
        $user_mysql_cate = M("user_mysql_default_cate");
        if (empty($high)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入身高";
            exit(json_encode($data_cc));
        }
        if (empty($weight)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入体重";
            exit(json_encode($data_cc));
        }
        if (empty($sex)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请选择性别";
            exit(json_encode($data_cc));
        }
        if (count($cate_ids) == 0) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请选择品类";
            exit(json_encode($data_cc));
        }

        //输出每个品类对应的推荐尺寸
        $result = [];
        //输出每个品类对应的量体字段和参考数据
        foreach ($cate_ids as $k => $v) {
            $cate_id2 = $cate_id1 = 0;
            if ($cate_ids[$k][0]) {
                $cate_id1 = $user_mysql_cate->where(['pid' => $cate_ids[$k][0], 'stype' => 1, 'sht_c' => 0, 'isdel' => 0])->find();
                $cate_id2 = $user_mysql_cate->where(['pid' => $cate_ids[$k][0], 'stype' => 1, 'sht_c' => 1, 'isdel' => 0])->find();
                if($cate_id1){
                    $result1 = "SELECT * FROM `fa_renshi_user_mysql_list` where `sex` =".$sex." and  cat_id = ".$cate_id1['id']  ." and  isdel= 0  order by abs(".$weight ."-`weight`) , abs(".$high."-`high`)    LIMIT 1 ";
                }else{
                    $result1 = '';
                }
                if($cate_id2){
                    $result2 = "SELECT * FROM `fa_renshi_user_mysql_list` where `sex` =".$sex." and  cat_id = ".$cate_id2['id']  ." and  isdel= 0  order by abs(".$weight ."-`weight`) , abs(".$high."-`high`)    LIMIT 1";
                }else{
                    $result2 = "SELECT * FROM `fa_renshi_user_mysql_list` where `sex` =".$sex." and  cat_id = ".$cate_ids[$k][0]  ." and  isdel= 0  order by abs(".$weight ."-`weight`) , abs(".$high."-`high`)    LIMIT 1";
                }
            }
            if($result1){
                $res = M()->query($result1);
                $res[0]['cat_name'] = $cate_id1['title']?$cate_id1['title']:$user_mysql_cate->where(['id' => $cate_ids[$k][0]])->getField('title');
                array_push($result,$res[0]);
            }
            if($result2){
                $res = M()->query($result2);
                $res[0]['cat_name'] = $cate_id2['title']?$cate_id2['title']: $user_mysql_cate->where(['id' => $cate_ids[$k][0]])->getField('title');
                array_push($result,$res[0]);
            }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['info'] = $result;
        exit(json_encode($data_cc));
    }


    //品类选择列表
    public function getCate()
    {
        $uid = UID;
        $user_mysql_cate = M("user_mysql_default_cate");
        $list = $user_mysql_cate->where(['pid' => 0, 'stype' => 2, 'uid' => $uid])->field('id,title')->order('id asc')->select();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['data']['list'] = $list;
        exit(json_encode($data_cc));
    }

    // //新建量体部位列表
    // public function litibuwei(){
    //     $list=['领围','前衣长','后衣长','肩宽','右袖长','左袖长','胸围','中腰','肚围','臀围','上臂围','小臂围','袖口围','袖夹围','前胸宽','后背宽','肚高点','（女）胸高点','（女）胸距离','前腰节','后腰节','裤/裙腰围','横档','膝围','小腿围','脚口','立档含腰','全档含腰','裤/裙长度','马甲前衣长','马甲后衣长','马甲胸围'];
    //     $data_cc['code']=200;
    //     $data_cc['msg']='查询成功';
    //     $data_cc['data']['list']=$list;
    //     exit(json_encode($data_cc));
    // }
    //新建量体部位列表
    public function litibuwei()
    {
        // $list['']
        $list[] = ['name' => '领围', 'key' => 'lw'];
        $list[] = ['name' => '前衣长', 'key' => 'qiancyi'];
        $list[] = ['name' => '后衣长', 'key' => 'hzhc'];
        $list[] = ['name' => '肩宽', 'key' => 'jiankuan'];
        $list[] = ['name' => '左袖长', 'key' => 'xiuchang'];
        $list[] = ['name' => '左袖长', 'key' => 'xiuchang'];
        $list[] = ['name' => '胸围', 'key' => 'cyxw'];
        $list[] = ['name' => '中腰', 'key' => 'zhonyao'];
        $list[] = ['name' => '肚围', 'key' => 'dw'];
        $list[] = ['name' => '臀围', 'key' => 'cptunwei'];
        $list[] = ['name' => '上臂围', 'key' => 'sbw'];
        $list[] = ['name' => '小臂围', 'key' => 'xbw'];
        $list[] = ['name' => '袖口围', 'key' => 'xkw'];
        $list[] = ['name' => '袖夹围', 'key' => 'xjw'];
        $list[] = ['name' => '前胸宽', 'key' => 'qxk'];
        $list[] = ['name' => '后背宽', 'key' => 'hbk'];
        $list[] = ['name' => '肚高点', 'key' => 'dgd'];
        $list[] = ['name' => '（女）胸高点', 'key' => 'nxgd'];
        $list[] = ['name' => '（女）胸距离', 'key' => 'nxjl'];
        $list[] = ['name' => '前腰节', 'key' => 'qyj'];
        $list[] = ['name' => '后腰节', 'key' => 'hyj'];
        $list[] = ['name' => '裤/裙腰围', 'key' => 'qkyw'];
        $list[] = ['name' => '横档', 'key' => 'hd'];
        $list[] = ['name' => '膝围', 'key' => 'qw'];
        $list[] = ['name' => '小腿围', 'key' => 'xtw'];
        $list[] = ['name' => '脚口', 'key' => 'jiaokou'];
        $list[] = ['name' => '立档含腰', 'key' => 'ldhy'];
        $list[] = ['name' => '全档含腰', 'key' => 'qdhy'];
        $list[] = ['name' => '裤/裙长度', 'key' => 'kuchang'];
        $list[] = ['name' => '马甲前衣长', 'key' => 'mjqyc'];
        $list[] = ['name' => '马甲后衣长', 'key' => 'mjhyc'];
        $list[] = ['name' => '马甲胸围', 'key' => 'mjxw'];
        // $list=['领围','前衣长','后衣长','肩宽','右袖长','左袖长','胸围','中腰','肚围','臀围','上臂围','小臂围','袖口围','袖夹围','前胸宽','后背宽','肚高点','（女）胸高点','（女）胸距离','前腰节','后腰节','裤/裙腰围','横档','膝围','小腿围','脚口','立档含腰','全档含腰','裤/裙长度','马甲前衣长','马甲后衣长','马甲胸围']; 
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }


    //保存私人定制信息
    public function save_info()
    {
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $detail = I('post.');
        $uid = UID;
        $minf_c = $detail['minf_c'] ?: [];
        //$customer = $detail['customer'] ? : [];
        $customer = I('post.');
        if (empty($customer['customer_name'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入顾客姓名";
            exit(json_encode($data_cc));
        }
        if (empty($customer['mobile'])) {
            //$data_cc['code'] = 0;
            //$data_cc['msg'] = "请输入电话";
            //exit(json_encode($data_cc));
        }
        if (empty($customer['high'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入身高";
            exit(json_encode($data_cc));
        }
        if (empty($customer['weight'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入体重";
            exit(json_encode($data_cc));
        }
        if (empty($customer['cat_id'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请选择品类";
            exit(json_encode($data_cc));
        }
        if (empty($customer['upper_id'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请传递上衣尺寸ID";
            exit(json_encode($data_cc));
        }
        $info = $detail['info'] ?: [];
        $tstx = $detail['tstx'] ?: [];
        $picc = $detail['picc'] ?: '';
        if (empty($info)) {
            //$data_cc['code'] = 0;
            //$data_cc['msg'] = "试衣备注参数错误";
            //exit(json_encode($data_cc));
        }
        $user_srdz_customer = M("user_srdz_customer");
        $customer_id = $customer['customer_id'];
        if ($customer_id) {
            $where['id'] = $customer_id;
            $where['uid'] = $uid;
            $where['isdel'] = 0;
            $m_info = $user_srdz_customer->where($where)->find();
            if (empty($m_info)) {
                $data_cc['code'] = 0;
                $data_cc['msg'] = "顾客信息不存在";
                exit(json_encode($data_cc));
            }
        }
        $customer_id = $this->add_customercc($customer);
        $this->add_tuanti($minf_c, $customer_id);
        $this->add_sybz($info, $customer_id);
        $this->add_tstx($tstx, $customer_id);
        $this->add_txphote($picc, $customer_id);
        $data_cc['code'] = 200;
        $data_cc['msg'] = "操作成功";
        exit(json_encode($data_cc));
    }

    //生成推荐数据
    public function recommend_data()
    {
        $detail = I('');
        $upper_id = $detail['upper_id'];
        $below_id = $detail['below_id'];
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $uid = UID;
        //衣服
        $where['isdel'] = 0;
        $where['uid'] = $uid;
        $where['id'] = $upper_id;
        //裤子
        $fyst['isdel'] = 0;
        $fyst['uid'] = $uid;
        $fyst['id'] = $below_id;
        $cate_upper_list = $user_mysql_list->where($where)->find();
        $cate_below_list = $user_mysql_listc->where($fyst)->find();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['upper_list'] = $cate_upper_list;
        $data_cc['below_list'] = $cate_below_list;
        exit(json_encode($data_cc));
    }

    //品类尺寸列表
    public function cate_desgin()
    {
        $cate_id = I('cate_id');
        if (empty($cate_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '品类ID不能为空';
            exit(json_encode($data_cc));
        }
        $user_mysql_cate = M("user_mysql_default_cate");
        $info = $user_mysql_cate->where(['id' => $cate_id, 'uid' => UID, 'stype' => 2, 'isdel' => 0])->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '品类信息不存在';
            exit(json_encode($data_cc));
        }
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $cate_upper = $user_mysql_cate->where(['pid' => $cate_id, 'stype' => 2, 'uid' => UID, 'sht_c' => 0, 'isdel' => 0])->select();
        $cate_upper_str = '';
        foreach ($cate_upper as $k => $v) {
            if ($cate_upper_str == '') {
                $cate_upper_str = $cate_upper_str . $v['id'];
            } else {
                $cate_upper_str = $cate_upper_str . ',' . $v['id'];
            }
        }
        $cate_below = $user_mysql_cate->where(['pid' => $cate_id, 'stype' => 2, 'uid' => UID, 'sht_c' => 1, 'isdel' => 0])->select();
        $cate_below_str = '';
        foreach ($cate_below as $bk => $bv) {
            if ($cate_below_str == '') {
                $cate_below_str = $cate_below_str . $bv['id'];
            } else {
                $cate_below_str = $cate_below_str . ',' . $bv['id'];
            }
        }
        $uid = UID;
        //衣服
        $where['isdel'] = 0;
        $where['uid'] = $uid;
        $where['_string'] = 'FIND_IN_SET(cat_id,"' . $cate_upper_str . '")';
        //裤子
        $fyst['isdel'] = 0;
        $fyst['uid'] = $uid;
        $fyst['_string'] = 'FIND_IN_SET(cat_id,"' . $cate_below_str . '")';
        $cate_upper_list = $user_mysql_list->where($where)->select();
        $cate_below_list = $user_mysql_listc->where($fyst)->select();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['upper_list'] = $cate_upper_list;
        $data_cc['below_list'] = $cate_below_list;
        exit(json_encode($data_cc));
    }

    //获取特殊体型列表
    public function get_tstxlist()
    {
        // $user_mysql_cate=M("user_mysql_cate");
        // $uid=UID;
        // $list=$user_mysql_cate->where(['pid'=>0,'stype'=>3,'uid'=>$uid])->field('id,title')->order('id asc')->select();
        // if($list){
        //     foreach($list as $k=>$val){
        //         $list[$k]['list']=$this->get_tstx_childs($val['id']);
        //     }
        // }
        // $data_cc['code']=200;
        // $data_cc['msg']='查询成功';
        // $data_cc['data']['list']=$list;
        // exit(json_encode($data_cc));
        $imgcate = M("imgcate");
        $uid = UID;
        $list = $imgcate->where(['pid' => 0, 'status' => 4, 'is_delete' => 0])->field('id,title')->order('id asc')->select();
        if ($list) {
            foreach ($list as $k => $val) {
                $list[$k]['list'] = $this->get_tstx_childs($val['id']);
            }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //查询体型下的图片信息
    public function get_tstx_childs($pid)
    {
        $img = M("img");
        $list = $img->where(['pid' => $pid, 'status' => 4, 'is_delete' => 0])->field('id,title,img')->order('id asc')->select();
        return $list;
    }

    //顾客信息新增
    function add_customercc($info)
    {
        $uid = UID;
        $user_srdz_customer = M("user_srdz_customer");
        $countc = $user_srdz_customer->where(['uid' => $uid, 'isdel' => 0])->count();
        $cocda = $countc + 1;
        $data['customer_name'] = $info['customer_name'];
        $data['sex'] = $info['sex'];
        $data['age'] = $info['age'];
        $data['high'] = $info['high'];
        $data['weight'] = $info['weight'];
        $data['cat_id'] = $info['cat_id'];
        $data['upper_id'] = $info['upper_id'];
        $data['below_id'] = $info['below_id'];
        $data['mobile'] = $info['mobile'];
        $data['remark'] = $info['customer_remark'] ?: '';
        $data['uid'] = $uid;
        $customer_id = $info['customer_id'];
        if ($customer_id) {
            $where['id'] = $customer_id;
            $where['uid'] = $uid;
            $where['isdel'] = 0;
            $m_info = $user_srdz_customer->where($where)->find();
            $user_srdz_customer->where(['uid' => $uid, 'id' => $m_info['id']])->save($data);
            $customer_id = $m_info['id'];
            // if(empty($m_info['customer_sn'])){
            //     $data['customer_sn']="SR000".$uid.$cocda;
            // }
        } else {
            $data['customer_sn'] = "SR000" . $uid . $cocda;
            $data['add_time'] = time();
            $customer_id = $user_srdz_customer->add($data);
        }

        // if($m_info){
        //     if(empty($m_info['customer_sn'])){
        //         $data['customer_sn']="SR000".$uid.$cocda;
        //     }
        //     $user_srdz_customer->where(['uid'=>$uid,'id'=>$m_info['id']])->save($data);
        //     $customer_id=$m_info['id'];
        // }else{

        // }
        return $customer_id;
    }

    //添加团体定制信息
    function add_tuanti($info, $customer_id)
    {
        $user_srdz_order = M("user_srdz_order");
        $uid = UID;
        $post = I('post.');
        if ($post) {
            $names = $post['names'];
            $bodysize = $post['bodysize'];
            $pro_size = $post['pro_size'];
            $shiyi_fitting = $post['shiyi_fitting'];
            $names = $post['names'];
            foreach ($names as $k => $val) {
                $data['names'] = $names[$k];
                $data['customer_id'] = $customer_id;
                $data['bodysize'] = $bodysize[$k];
                $data['pro_size'] = $pro_size[$k];
                $data['shiyi_fitting'] = $shiyi_fitting[$k];
                $data['uid'] = $uid;
                $data['add_time'] = time();
                $fsger[] = $data;
            }
        }
        if ($fsger) {
            foreach ($fsger as $k1 => $vals) {
                $m_info = $user_srdz_order->where(['uid' => $uid, 'customer_id' => $vals['customer_id'], 'names' => $vals['names'], 'isdel' => 0])->find();
                if ($m_info) {
                    $user_srdz_order->where(['uid' => $uid, 'customer_id' => $customer_id, 'id' => $m_info['id']])
                        ->save(['bodysize' => $vals['bodysize'], 'pro_size' => $vals['pro_size'], 'shiyi_fitting' => $vals['shiyi_fitting']]);
                } else {
                    $user_srdz_order->add($vals);
                }
            }
        }

    }

    //添加团体定制信息
    function add_tuanti_bak($info, $customer_id)
    {
        $user_srdz_order = M("user_srdz_order");
        $uid = UID;
        if ($info) {
            $names = $info['names'];
            $bodysize = $info['bodysize'];
            $pro_size = $info['pro_size'];
            $shiyi_fitting = $info['shiyi_fitting'];
            foreach ($names as $k => $val) {
                $data['names'] = $names[$k];
                $data['customer_id'] = $customer_id;
                $data['bodysize'] = $bodysize[$k];
                $data['pro_size'] = $pro_size[$k];
                $data['shiyi_fitting'] = $shiyi_fitting[$k];
                $data['uid'] = $uid;
                $data['add_time'] = time();
                $fsger[] = $data;
            }
        }
        if ($fsger) {
            foreach ($fsger as $k1 => $vals) {
                $m_info = $user_srdz_order->where(['uid' => $uid, 'customer_id' => $vals['customer_id'], 'names' => $vals['names'], 'isdel' => 0])->find();
                if ($m_info) {
                    $user_srdz_order->where(['uid' => $uid, 'customer_id' => $customer_id, 'id' => $m_info['id']])
                        ->save(['bodysize' => $vals['bodysize'], 'pro_size' => $vals['pro_size'], 'shiyi_fitting' => $vals['shiyi_fitting']]);
                } else {
                    $user_srdz_order->add($vals);
                }
            }
        }

    }

    //添加试衣备注
    function add_sybz($info, $customer_id)
    {
        $post = I('post.');
        $uid = UID;
        $data['taomayi'] = $post['taomayi'];
        $data['customer_id'] = $customer_id;
        $data['palin'] = $post['palin'];
        $data['jianxie'] = $post['jianxie'];
        $data['houyaojie'] = $post['houyaojie'];
        $data['uid'] = $uid;
        $user_srdz_sybz = M("user_srdz_sybz");
        $m_info = $user_srdz_sybz->where(['uid' => $uid, 'customer_id' => $customer_id, 'isdel' => 0])->find();
        if ($m_info) {
            $user_srdz_sybz->where(['uid' => $uid, 'id' => $m_info['id'], 'customer_id' => $customer_id])->save($data);
        } else {
            $data['add_time'] = time();
            $user_srdz_sybz->add($data);
        }
    }

    //添加试衣备注
    function add_sybz_bak($info, $customer_id)
    {
        $uid = UID;
        $data['taomayi'] = $info['taomayi'];
        $data['customer_id'] = $customer_id;
        $data['palin'] = $info['palin'];
        $data['jianxie'] = $info['jianxie'];
        $data['houyaojie'] = $info['houyaojie'];
        $data['uid'] = $uid;
        $user_srdz_sybz = M("user_srdz_sybz");
        $m_info = $user_srdz_sybz->where(['uid' => $uid, 'customer_id' => $customer_id, 'isdel' => 0])->find();
        if ($m_info) {
            $user_srdz_sybz->where(['uid' => $uid, 'id' => $m_info['id'], 'customer_id' => $customer_id])->save($data);
        } else {
            $data['add_time'] = time();
            $user_srdz_sybz->add($data);
        }
    }

    function add_tstx($info, $customer_id)
    {
        $user_srdz_tstx = M("user_srdz_tstx");
        $uid = UID;
        $post = I('post.');
        if ($post) {
            $cid = $post['cid'];
            $remark = $post['remark'];
            foreach ($cid as $k => $val) {
                $data['cid'] = $val;
                $data['pid'] = 4;
                $data['customer_id'] = $customer_id;
                $data['remark'] = $remark[$k];
                $data['uid'] = $uid;
                $data['add_time'] = time();
                $fsger[] = $data;
            }
        }
        if ($fsger) {
            foreach ($fsger as $k1 => $vals) {
                $m_info = $user_srdz_tstx->where(['uid' => $uid, 'pid' => $vals['pid'], 'customer_id' => $customer_id, 'isdel' => 0])->find();
                if ($m_info) {
                    $user_srdz_tstx->where(['uid' => $uid, 'id' => $m_info['id'], 'customer_id' => $customer_id])->save(['cid' => $vals['cid'], 'remark' => $vals['remark']]);
                } else {
                    $user_srdz_tstx->add($vals);
                }
            }
        }
    }

    function add_tstx_bak($info, $customer_id)
    {
        $user_srdz_tstx = M("user_srdz_tstx");
        $uid = UID;
        if ($info) {
            $cid = $info['cid'];
            $remark = $info['remark'];
            foreach ($cid as $k => $val) {
                $data['cid'] = $val;
                $data['pid'] = 4;
                $data['customer_id'] = $customer_id;
                $data['remark'] = $remark[$k];
                $data['uid'] = $uid;
                $data['add_time'] = time();
                $fsger[] = $data;
            }
        }
        if ($fsger) {
            foreach ($fsger as $k1 => $vals) {
                $m_info = $user_srdz_tstx->where(['uid' => $uid, 'pid' => $vals['pid'], 'customer_id' => $customer_id, 'isdel' => 0])->find();
                if ($m_info) {
                    $user_srdz_tstx->where(['uid' => $uid, 'id' => $m_info['id'], 'customer_id' => $customer_id])->save(['cid' => $vals['cid'], 'remark' => $vals['remark']]);
                } else {
                    $user_srdz_tstx->add($vals);
                }
            }
        }
    }

    //添加体型照片
    function add_txphote($picc, $customer_id)
    {
        $user_srdz_pic = M("user_srdz_pic");
        $uid = UID;
        if ($picc) {
            $data['picc'] = $picc;
            $data['customer_id'] = $customer_id;
            $data['uid'] = $uid;
            $data['add_time'] = time();
        }
        if ($data) {
            $m_info = $user_srdz_pic->where(['uid' => $uid, 'customer_id' => $customer_id, 'isdel' => 0])->find();
            if ($m_info) {
                $user_srdz_pic->where(['uid' => $uid, 'customer_id' => $customer_id, 'id' => $m_info['id']])->save(['picc' => $data['picc']]);
            } else {
                $user_srdz_pic->add($data);
            }
        }
    }

    //查询体型下的图片信息
    public function get_childs($cat_id)
    {
        $user_tstx_pic = M("user_tstx_pic");
        $list = $user_tstx_pic->where(['cat_id' => $cat_id])->field('id,title,pic')->order('id asc')->select();
        return $list;
    }


}
